package com.csweimei.rentmanagementtreasure.enterprise.viewModel;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.adapter.ImageAdapter;
import com.csweimei.rentmanagementtreasure.http.entity.EntHomeDailyBean;
import com.csweimei.rentmanagementtreasure.pop.ImageShowPop;
import com.csweimei.rentmanagementtreasure.pop.PopUtils;
import com.csweimei.rentmanagementtreasure.utils.ValidateUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;

public class EntDPItem extends MultiItemViewModel {

    public EntDPItem(@NonNull BaseViewModel viewModel) {
        super(viewModel);
    }


    public ObservableField<EntHomeDailyBean.DataDTO.DailyDTO> entity = new ObservableField<>();
    public ObservableField<ImageAdapter> adapter = new ObservableField<>(new ImageAdapter());

    public void setData(EntHomeDailyBean.DataDTO.DailyDTO bean) {
        entity.set(bean);
        List<String> list = new ArrayList<>();
        if (ValidateUtils.isNotEmptyObjectOrString(entity.get())){
            if (entity.get().getImgsrc().contains(",")){
                list.addAll(Arrays.asList(entity.get().getImgsrc().split(",")));
            }else {
                list.add(entity.get().getImgsrc());
            }
            adapter.get().setList(list);
            adapter.get().addChildClickViewIds(R.id.img);
            adapter.get().setOnItemChildClickListener((adapter1, view, position) -> {
                showImgPop( adapter.get().getData().get(position));
            });
        }

    }

    private void showImgPop(String s) {
        ImageShowPop imageShowPop = new ImageShowPop(viewModel.mActivity,s);
        PopUtils.showPop(viewModel.mActivity,imageShowPop,false);
    }
}
